float4x4 World;
float4x4 View;
float4x4 Projection;

float4 LightColor;
float3 LightDirection;

float4 AmbientColor;

texture Texture;




sampler ModelTextureSampler = sampler_state
{
    // all samplers must specify which texture they are sampling from.
    Texture = <Texture>;
    
    //The MinFilter describes how the texture sampler will read for pixels
    //larger than one texel.
    MinFilter = Linear;
    //The MagFilter describes how the texture sampler will read for pixels
    //smaller than one texel.
    MagFilter = Linear;
    //The MipFilter describes how the texture sampler will combine different
    //mip levels of the texture.
    MipFilter = Linear;

    //The AddressU and AddressV values describe how the texture sampler will treat
    //a texture coordinate that is outside the range of [0-1].
    //In this case, it "clamps", where all values less than 0 are treated as 0, 
    //and all values greater than 1 are treated as 1.  
    AddressU = Clamp;
    AddressV = Clamp;
};



struct VertexShaderInput
{
    float4 Position : POSITION0;
	float3 Normal : NORMAL0;
	float4 Color : COLOR0;
	float2 TextureCoordinate : TEXCOORD0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float4 Color : COLOR0;
	float2 TextureCoordinate : TEXCOORD0;
};




VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);
	
	float3 worldNormal =  mul(input.Normal, World);
	float diffuseIntensity = saturate( dot(-LightDirection, worldNormal));
	float4 diffuseColor = LightColor * diffuseIntensity;
	float4 lightingColor = diffuseColor + AmbientColor;
	
	output.Color = input.Color * lightingColor;
	
	output.TextureCoordinate = input.TextureCoordinate;
	
    return output;
}




float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
	float4 textureColor = tex2D(ModelTextureSampler, input.TextureCoordinate);
	
	return input.Color * textureColor;
}





technique Technique1
{
    pass Pass1
    {
        VertexShader = compile vs_1_1 VertexShaderFunction();
        PixelShader = compile ps_1_1 PixelShaderFunction();
    }
}
